﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QFlow.Core
{
    public static class Authentication
    {
        public static void SetAuthenticationToken(IUser Token)
        {
            CurrentUser = Token;
        }
        public static void RemoveAuthenticationToken()
        {
            CurrentUser = null;
        }
        public static IUser CurrentUser { set; get; }
        public static bool IsAuthenticated { get { return CurrentUser != null; } }
        public static bool HasPermission(object PermissionKey)
        {
            if (CurrentUser == null)
                throw new InvalidOperationException("No Authentication token is set");
            return CurrentUser.HasPermission(PermissionKey);
        }
        public static bool HasPermission(string PermissionName)
        {
            if (CurrentUser == null)
                throw new InvalidOperationException("No Authentication token is set");
            return CurrentUser.HasPermission(PermissionName);
        }
    }
}
